<template>
  <div class="container" ref="mainCon">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="searchBox searchInputWidth">
        <el-form :inline="true" :model="filterField" ref="accountForm">
          <el-col :lg="8" :xl="6">
            <el-form-item label="人员姓名" class="row-padding-bottom">
              <el-input
                placeholder="请输入姓名或身份证号"
                clearable
                v-model="filterField.keyword"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-form-item>
            <el-button
              type="primary"
              icon="icon iconfont iconchazhao1"
              @click="searchList"
              class="searchBtn"
            >
              <span>搜索</span>
            </el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <div class="spacing"></div>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
      >
        <!-- 列表 -->
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          v-loading="loading"
          style="border: 1px solid #dfe6ec"
          @sort-change="filterHandler"
        >
          <el-table-column
            align="center"
            prop="ip"
            label="身份证照片"
            :formatter="formatTd"
          >
            <template slot-scope="scope">
              <el-image
                v-if="scope.row.idcardPhoto"
                style="width: 50px; height: 50px"
                :src="scope.row.idcardPhoto"
                :preview-src-list="scope.row.idcardImgList"
              >
              </el-image>
              <el-image
                v-else
                src="../../../static/img/employee/card.png"
                alt=""
                style="width: 50px; height: 50px"
              />
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="name"
            label="姓名"
            :formatter="formatTd"
          />
          <el-table-column
            align="center"
            prop="idcard"
            label="身份证号"
            :formatter="formatTd"
          />
          <el-table-column
            align="center"
            prop="sexValue"
            label="性别"
            :formatter="formatTd"
          />
          <el-table-column
            align="center"
            prop="nationalityValue"
            label="民族"
            :formatter="formatTd"
          />
          <el-table-column
            align="center"
            prop="inputDate"
            width="180px"
            sortable="custom"
            label="录入时间"
            :formatter="formatTd"
          />
          <el-table-column align="left" label="操作" fixed="right" width="100">
            <template slot-scope="scope">
              <el-link type="primary" @click="editStatus(scope.row)"
                >修改</el-link
              >
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无相关信息"></emptyTable>
          </div>
        </el-table>
        <!-- filterField为搜索条件 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
          @getpageNo="getpageNo"
          @getpageSize="getpageSize"
        ></Pagination>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'rosterchange',
  data() {
    return {
      titleText: '花名册修改',
      filterField: {
        keyword: '',
        orderBy: 'inputDate:asc',
      },
      tableData: [],
      loading: true,
      isShow: false,
      requestUrl: 'api-e/cs/employee/expand/emp',
    }
  },
  mounted() {
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
  },
  methods: {
    getTableList(data) {
      this.tableData = data
      this.loading = false
      if (this.tableData.length < 1) {
        this.isShow = true
      }
    },
    searchList() {
      this.$nextTick(function () {
        this.$refs.pagination.getTableListData()
      })
    },
    filterHandler(value) {
      if (value.order == 'ascending') {
        this.filterField.orderBy = 'inputDate:asc'
      } else {
        this.filterField.orderBy = 'inputDate:desc'
      }
      this.$refs.pagination.getTableListData()
    },
    // 修改员工信息
    editStatus(item) {
      this.$router.push({
        path: '/home/systemSettings/rosterEdit',
        name: 'rosterEdit',
        query: { id: item.id },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/systemSettings/rosterChange',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>
<style lang="less" scoped></style>
